Clone less with an extra `Registry` impl
authorAlex Crichton <alex@alexcrichton.com>
Mon, 8 Jun 2015 17:58:15 +0000 (10:58 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 8 Jun 2015 17:58:15 +0000 (10:58 -0700)
src/cargo/core/registry.rs
src/cargo/sources/path.rs

index 4bd13c29e7d5ea9bc9b29bdfaa410da55e680c46..c9a65f62d9a02a94213319f05c385949ec43f84f 100644 (file)
@@ -19,6 +19,13 @@ impl Registry for Vec<Summary> {
     }
 }
 
+impl Registry for Vec<Package> {
+    fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+        Ok(self.iter().filter(|pkg| dep.matches(pkg.summary()))
+               .map(|pkg| pkg.summary().clone()).collect())
+    }
+}
+
 /// This structure represents a registry of known packages. It internally
 /// contains a number of `Box<Source>` instances which are used to load a
 /// `Package` from.
index a3f058573dcd505c985ce891355f151222fceb73..80f9195420a5ed6387601ba3d6479fbdf0906821 100644 (file)
@@ -59,7 +59,7 @@ impl<'cfg> PathSource<'cfg> {
         }
     }
 
-    pub fn read_packages(&self) -> CargoResult<Vec<Package>> {
+    fn read_packages(&self) -> CargoResult<Vec<Package>> {
         if self.updated {
             Ok(self.packages.clone())
         } else if self.id.is_path() && self.id.precise().is_some() {
@@ -272,10 +272,7 @@ impl<'cfg> Debug for PathSource<'cfg> {
 
 impl<'cfg> Registry for PathSource<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
-        let mut summaries: Vec<Summary> = self.packages.iter()
-                                              .map(|p| p.summary().clone())
-                                              .collect();
-        summaries.query(dep)
+        self.packages.query(dep)
     }
 }